/**
 * Copyright (c) 2015 www.smarthome.com All rights reserved. <br />
 * 本软件源代码版权归xxxx公司,未经许可不得任意复制与传播.<br />
 *
 */
package com.smarthome.domain.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * 
 * 实名认证时用到的证件类型
 *
 * @author KongXiangyu
 *
 * @since 1.0
 */
public enum CredentialType {
    /** 第二代居民身份证 */
    ID_2NDGEN(1, "第二代居民身份证"),
    /** 营业执照 */
    BUSINESS_LICENSE(2, "营业执照");

    int type;

    String name;
    
    private static Map<Integer,String> typeMap = new HashMap<Integer,String>();

    private CredentialType(int type, String name) {
        this.type = type;
        this.name = name;
    }
    
    static{
    	for(CredentialType t : CredentialType.values()){
    		typeMap.put(t.getType(), t.getName());
    	}
    }

    
    public static String getNameByCode(Integer code){
    	
    	return typeMap.get(code);
    }
    /**
     * 获取证件类型
     * 
     * @return
     */
    public int getType() {
        return type;
    }

    /**
     * 获取证件名称
     * 
     * @return
     */
    public String getName() {
        return name;
    }

    /**
     * 
     * @param credentialType
     * @return
     */
    public static CredentialType getByType(int credentialType) {
        for (CredentialType ct : values()) {
            if (ct.getType() == credentialType) {
                return ct;
            }
        }
        return null;
    }
}
